/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import Taro, { Component } from '@tarojs/taro'
import { Swiper } from '@tarojs/components'
// import { AtTabs, AtTabsPane } from 'taro-ui'
import { AtModal, AtModalHeader, AtModalContent, AtModalAction } from "taro-ui"

// project
import { CPage, CContent, CHeader, CFooter, CFloat, CAround, CBetween, CCenter, CRow, CWrap, CLine, CHand, CItemX, CItemY, CText, CLabel, CSvg, CImage, CButton, CColumn } from '../../library/comp';
import { Base64, Gen, Time, Zip, Session, Storage, Toast} from '../../library/func';
import Icon from '../../project/style/icon';
import Http from '../../project/func/http/http'

// 引用组件
import { Addcbtn, Cbtn, Chead, Destop, Editcunit, Ibottom, Ibottomp, Listunitone, Listunittwo, Listunitthree, LogoLine, LogoLinep, Tabheader } from '../../project/comp'

/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class UserCollect extends Component {

	constructor(props) {
		super(props);

		/**
		 * state
		 */
		this.state = {
			typeLlist:['动态','课堂'],
			active:'动态',
			list:[],
		}
	}
	/*------------------------------------------------------------------------------------
	 * 声明周期
	 *-----------------------------------------------------------------------------------*/
	// willMount
	componentWillMount () {
		this.getCollect()
	}

	// didMount
	componentDidMount(){
		this.getCollect()
	}

	/*------------------------------------------------------------------------------------
	 * 事件处理
	 *-----------------------------------------------------------------------------------*/
    // onRedirect
    onRedirect(url){
        wx.redirectTo({
            url: url
        })
    }
    // onNavigate
    onNavigate(url){
        wx.navigateTo({
            url: url
        })
    }
    //onNavigateBack
    onNavigateBack(num=1){
        wx.navigateBack({
            delta: num
        })                    
    }
		
    /*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/
	// 调用接口
	getCollect(){
		Http.Loading({
			url:'collect/list.php',
			data:{
				enum_type:this.state.active
			},
			success:(data)=>{
				this.setState({
					list:data
				},()=>{
					console.log('listttttttttttttttttttttttttttttttt',this.state.list)
				})
			}
		})
	}
    
	// 点击标签页
	changeCurrent (value) {
		console.log('vvvvvvvvvvvvvvvvvvvvvv',value)
		this.setState({
			current: value
		})
	}

	// 改变tabs当前项
	changActive = ( type,e ) =>{
		// console.log('type',type)
        this.setState({
            active:type,
        },()=>{
			this.getCollect()
		})
    }

	// 取消收藏
	deleteone(id,e){

		Http.post({
			url:'collect/logic/cancel.php',
			data:{
				enum_type:this.state.active,
				fk_id:id
			},
			success:(data)=>{
				console.log('取消关注成功msg',data)
				Toast.text('取消关注成功')
				this.getCollect()
			}
		})
	}

	config = {
        navigationBarTitleText: '我的收藏'
    }


	/**
	 * 渲染
	 */
	render() {

		// 渲染
		return (
			<CPage>
				<CContent>
					<CLine class="f1" h="45" x="center" bg="#C3AB7A">
						<CBetween bg="white" px='80'>
							{
								this.state.typeLlist.map( item => {
									return (
										this.state.active == item ?
											<CHand class="f03" y="center" h="45" x="center" onClick={ this.changActive.bind(this,item) }>
												<CText size="16" mt="2" bb="#D7C361 6 solid" py='10'>{item}</CText>
											</CHand>
										:
											<CHand class="f03" y="center" h="45" x="center" onClick={ this.changActive.bind(this,item) }>
												<CText size="16" pb='2'>{item}</CText>
											</CHand>
									)
								})
							}
							
						</CBetween>
					</CLine>

                    {/* 收藏列表 */}
					{
						this.state.list.map( item => {
							return(
								<Listunitthree data={item} onFunction={this.deleteone.bind(this,item.id)}></Listunitthree>
							)
						})
					}
                    
				</CContent>
			</CPage>
		);
	}
};